package com.example.demo;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-11-2
 * Time:14:46
 */

@Component
public class Agency implements MethodInterceptor {

    @Autowired
    private Task station;

    public Task getProxyObject() {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(station.getClass());
        enhancer.setCallback(this);
        Task obj = (Task) enhancer.create();
        return obj;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        Object result = method.invoke(station, objects);
        return result;
    }

}


